package work.xiaohong.gupiao.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import work.xiaohong.gupiao.dao.BaoxianMapper;
import work.xiaohong.gupiao.pojo.Baoxian;
import work.xiaohong.gupiao.service.BaoxianService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BaoxianServiceImpl implements BaoxianService {

    @Autowired
    private BaoxianMapper baoxianMapper;


    /**
     * 条件+分页查询Baoxian
     * @param baoxian 查询条件
     * @param page 页码
     * @param size 页大小
     * @return 分页结果
     */
    @Override
    public Page<Baoxian> findPage(Baoxian baoxian, int page, int size){
        // 构建查询条件
        QueryWrapper<Baoxian> queryWrapper = new QueryWrapper<Baoxian>(baoxian);
        // 构建分页
        Page pg = new Page(page, size);
        // 分页查询
        return baoxianMapper.selectPage(pg, queryWrapper);
    }

    /**
     * 分页查询Baoxian
     * @param page
     * @param size
     * @return
     */
    @Override
    public Page<Baoxian> findPage(int page, int size){
        // 构建分页
        Page pg = new Page(page, size);
        // 分页查询
        return baoxianMapper.selectPage(pg, null);
    }

    /**
     * 多条件搜索方法Baoxian
     * @param baoxian
     * @return
     */
    @Override
    public List<Baoxian> findList(Baoxian baoxian){
        // 构建查询条件
        QueryWrapper<Baoxian> queryWrapper = new QueryWrapper<Baoxian>(baoxian);
        // 查询数据
        return baoxianMapper.selectList(queryWrapper);
    }

    /**
     * 根据ID删除Baoxian
     * @param id
     */
    @Override
    public void delete(Integer id){
        baoxianMapper.deleteById(id);
    }

    /**
     * 根据ID修改Baoxian
     * @param baoxian
     */
    @Override
    public void update(Baoxian baoxian){
        baoxianMapper.updateById(baoxian);
    }

    /**
     * 增加Baoxian
     * @param baoxian
     */
    @Override
    public void add(Baoxian baoxian){
        baoxianMapper.insert(baoxian);
    }

    /**
     * 根据ID查询Baoxian
     * @param id
     * @return
     */
    @Override
    public Baoxian findById(Integer id){
        return  baoxianMapper.selectById(id);
    }

    /**
     * 查询全部Baoxian数据
     * @return
     */
    @Override
    public List<Baoxian> findAll() {
        return baoxianMapper.selectList(null);
    }
}
